﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="bas_dept.aspx.cs" Inherits="bas_dept" %>
<%@ Register Src="~/UserControls/ucFavorite.ascx" TagName="ucFavorite" TagPrefix="Kerry" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" runat="Server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="Server">
  <%--<script src="../../Scripts/jquery-1.7.1.js"></script>--%>
  <script type="text/jscript" lang="javascript">

    function RowChanged(e) {
      //alert('bb');
      var hidShip = e.parentElement.parentElement.cells[1].getElementsByTagName('input')[0]
      hidShip.value = 'Y';
      //TargetBaseControl = document.getElementById('<%= this.DV1.ClientID %>_tb1');
      //for (var rowId = 1; rowId < TargetBaseControl.rows.length; ++rowId) {
      //    var txtShip = TargetBaseControl.rows[rowId].cells[0].getElementsByTagName("input")[0];
      //    txtShip.style.display = "none";
      /// }


    };

    $(document).ready(function () {
      $("input[name*='DataPager1']").click(function () {
        //判斷該頁是否資料有被變更
        $("input[id*='hidCHANGED']").each(function (i) {
          if (this.value == 'Y') {
            if (confirm('此頁資料已有異動，是否要存檔？'))
            { $("input[id*='hidSAVE']")[0].value = 'Y'; }

            else
            { $("input[id*='hidSAVE']")[0].value = ''; }

          };
        }
     )

      }

    );
    });
  </script>

  <table class="ConditionTable">
    <tr>
      <th colspan="2"><Kerry:ucFavorite ID="ucFavorite" runat="server" />部門維護</th>
    </tr>
    <tr>
      <td>部門代號 :
                <asp:TextBox ID="txtDEPT_ID" runat="server"></asp:TextBox>
      </td>
      <td>部門名稱：<asp:TextBox ID="txtDEPT_NAME" runat="server"></asp:TextBox>
      </td>
    </tr>

    <tr>
      <td colspan="2">

        <asp:Button ID="btn_search" runat="server" Text="搜尋" OnClick="btnQuery_Click" />
        <asp:Button ID="btn_save" runat="server" Text="存檔" OnClick="btn_save_Click" />
        <asp:Button ID="btn_exist" runat="server" Text="離開" OnClick="btn_exist_Click" />
      </td>
    </tr>
  </table>
  <br />
  <asp:Label ID="lbl_Message" runat="server" Text="" ForeColor="Red"></asp:Label><asp:HiddenField ID="hid_Message" Value="資料確定要刪除？" runat="server" />
  <asp:HiddenField ID="hidSAVE" runat="server" />

  <asp:ListView ID="DV1" runat="server" DataKeyNames="DEPT_ID" InsertItemPosition="LastItem" OnItemCanceling="DV1_ItemCanceling" OnItemEditing="DV1_ItemEditing" OnItemDeleting="DV1_ItemDeleting" OnItemInserting="DV1_ItemInserting" OnItemUpdating="DV1_ItemUpdating" OnPagePropertiesChanging="DV1_PagePropertiesChanging" OnPagePropertiesChanged="DV1_PagePropertiesChanged">
    <EditItemTemplate>
      <tr style="background-color: #FFCC66; color: #000080;">
        <td>
          <asp:Button ID="btn_save" runat="server" CommandName="Update" Text="存檔" ValidationGroup="EDIT" />
          <asp:Button ID="btn_cancel" runat="server" CommandName="Cancel" Text="取消" />
        </td>
        <td>
          <asp:Label ID="lblDEPT_ID" runat="server" Width="80%" Text='<%# Eval("DEPT_ID") %>' />
          <asp:TextBox ID="txtDEPT_ID_G" runat="server" Text='<%# Bind("DEPT_ID") %>' Visible="false" />
        </td>
        <td>
          <asp:TextBox ID="txtDEPT_NAME_G" MaxLength="30" runat="server" Width="95%" Text='<%# Bind("DEPT_NAME") %>' />
          <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ValidationGroup="EDIT" ControlToValidate="txtDEPT_NAME_G" runat="server" SetFocusOnError="true" ErrorMessage="不可空白" ForeColor="Red"></asp:RequiredFieldValidator>
        </td>
        <td>

          <asp:TextBox ID="txtUSER_ID" MaxLength="17" runat="server" Width="95%" Text='<%# Bind("USER_ID") %>' OnTextChanged="txtUSER_ID_TextChanged" AutoPostBack="True" />
          <asp:Label ID="lblUSER_NAME" runat="server" Text='<%# Eval("USER_NAME") %>' />
          

        </td>
        <td>
          <asp:TextBox ID="txtE_MAIL" MaxLength="50" runat="server" Width="95%" Text='<%# Bind("E_MAIL") %>' />
          <asp:RegularExpressionValidator ID="RegularExpressionValidator9" ValidationGroup="EDIT" ForeColor="Red"  runat="server"  ControlToValidate="txtE_MAIL" SetFocusOnError="true" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" ErrorMessage="Invalid Email" BorderStyle="None"></asp:RegularExpressionValidator>
        </td>
        <td>
          <asp:TextBox ID="txtPARENT_DEPT_ID" MaxLength="17" runat="server" Width="95%" Text='<%# Bind("PARENT_DEPT_ID") %>' AutoPostBack="true" />
          <asp:CompareValidator ID="CompareValidator1" runat="server" ErrorMessage="不可與部門代號相同" ControlToValidate="txtPARENT_DEPT_ID" ControlToCompare="txtDEPT_ID_G" ValidationGroup="EDIT" Operator="NotEqual" ForeColor="Red" SetFocusOnError="true"></asp:CompareValidator>
        </td>
        
      </tr>
    </EditItemTemplate>
    <EmptyDataTemplate>
      <table id="tb1" runat="server" style="background-color: #FFFFFF; border-collapse: collapse; border-color: #999999; border-style: none; border-width: 1px;">
        <tr>
          <td>未傳回資料。</td>
        </tr>
      </table>
    </EmptyDataTemplate>
    <InsertItemTemplate>
      <tr style="">
        <td>
          <asp:Button ID="btn_save" runat="server" CommandName="Insert" Text="新增" ValidationGroup="INSERT" />
          <asp:Button ID="btn_cancel" runat="server" CommandName="Cancel" Text="清除" />
        </td>
        <td>
          <asp:TextBox ID="txtDEPT_ID_G" MaxLength="17" runat="server" Width="95%" Text='<%# Bind("DEPT_ID") %>' />
          <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ValidationGroup="INSERT" ControlToValidate="txtDEPT_ID_G" runat="server" SetFocusOnError="true" ForeColor="Red" ErrorMessage="不可空白"></asp:RequiredFieldValidator>
        </td>
        <td>
          <asp:TextBox ID="txtDEPT_NAME_G" MaxLength="30" runat="server" Width="95%" Text='<%# Bind("DEPT_NAME") %>' />
          <asp:RequiredFieldValidator ID="RequiredFieldValidator2" ValidationGroup="INSERT" ControlToValidate="txtDEPT_NAME_G" runat="server" SetFocusOnError="true" ForeColor="Red" ErrorMessage="不可空白"></asp:RequiredFieldValidator>
        </td>
        <td>
          <asp:TextBox ID="txtUSER_ID" MaxLength="30" runat="server" Width="95%" Text='<%# Bind("USER_ID") %>' OnTextChanged="txtUSER_ID_TextChanged" AutoPostBack="True" />
          <asp:Label ID="lblUSER_NAME" runat="server" Text='<%# Eval("USER_NAME") %>' />
          <asp:RegularExpressionValidator ID="RegularExpressionValidator2" ValidationGroup="INSERT" ForeColor="Red"  runat="server"  ControlToValidate="txtUSER_ID" SetFocusOnError="true" ValidationExpression="" ErrorMessage="" BorderStyle="None"></asp:RegularExpressionValidator>
        </td>
        <td>
          <asp:TextBox ID="txtE_MAIL" MaxLength="50" runat="server" Width="95%" />
          <asp:RegularExpressionValidator ID="RegularExpressionValidator1" ValidationGroup="INSERT" ForeColor="Red"  runat="server"  ControlToValidate="txtE_MAIL" SetFocusOnError="true" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" ErrorMessage="Invalid Email" BorderStyle="None"></asp:RegularExpressionValidator>
        </td>
        <td>
          <asp:TextBox ID="txtPARENT_DEPT_ID" MaxLength="17" runat="server" Width="95%" Text='<%# Bind("PARENT_DEPT_ID") %>' />
          <asp:CompareValidator ID="CompareValidator1" runat="server" ErrorMessage="不可與部門代號相同" ControlToValidate="txtPARENT_DEPT_ID" ControlToCompare="txtDEPT_ID_G" ValidationGroup="INSERT" Operator="NotEqual" ForeColor="Red" SetFocusOnError="true"></asp:CompareValidator>
        </td>
        
      </tr>
    </InsertItemTemplate>
    <ItemTemplate>
      <tr style="background-color: #FFFBD6; color: #333333;">
        <td>
          <asp:Button ID="btn_delete" runat="server" CommandName="Delete" Text="刪除" OnClientClick="if (!confirm('資料確定刪除？')){return false;}" />
          <%--<asp:Button ID="btn_edit" runat="server" CommandName="Edit" Text="編輯" />--%>
        </td>
        <%--<td>
                    <asp:Label ID="lblDEPT_ID" runat="server" Text='<%# Eval("DEPT_ID") %>' />
                </td>
                <td>
                    <asp:Label ID="lblDEPT_NAME" runat="server" Text='<%# Eval("DEPT_NAME") %>' />
                </td>
                <td>
                    <asp:Label ID="lblUSER_ID" runat="server" Text='<%# Eval("USER_ID_NAME") %>' />
                </td>
                <td>
                    <asp:Label ID="lblPARENT_DEPT_ID" runat="server" Text='<%# Eval("PARENT_DEPT_ID") %>' />
                </td>
                <td>
                    <asp:Label ID="lblE_MAIL" runat="server" Text='<%# Eval("E_MAIL") %>' />
                </td>    --%>
        <td>
          <asp:Label ID="lblDEPT_ID" runat="server" Width="80%" Text='<%# Eval("DEPT_ID") %>' />
          <asp:TextBox ID="txtDEPT_ID_G" runat="server" Text='<%# Bind("DEPT_ID") %>' Visible="false" />
          <asp:HiddenField ID="hidCHANGED" Value="" runat="server" />
        </td>
        <td>
          <asp:TextBox ID="txtDEPT_NAME_G" MaxLength="30" runat="server" Width="95%" onchange="RowChanged(this);" Text='<%# Bind("DEPT_NAME") %>' />
          <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ValidationGroup="EDIT" ControlToValidate="txtDEPT_NAME_G" runat="server" SetFocusOnError="true" ErrorMessage="不可空白" ForeColor="Red"></asp:RequiredFieldValidator>
        </td>
        <td>
          <asp:TextBox ID="txtUSER_ID" MaxLength="17" runat="server" Width="95%" onchange="RowChanged(this);" Text='<%# Bind("USER_ID") %>' OnTextChanged="txtUSER_ID_TextChanged" AutoPostBack="True" />
          <asp:Label ID="lblUSER_NAME" runat="server" Text='<%# Eval("USER_NAME") %>' />
          <asp:RegularExpressionValidator ID="RegularExpressionValidator2" ValidationGroup="EDIT" ForeColor="Red"  runat="server"  ControlToValidate="txtUSER_ID" SetFocusOnError="true" ValidationExpression="" ErrorMessage="" BorderStyle="None"></asp:RegularExpressionValidator>
        </td>
          <td>
          <asp:TextBox ID="txtE_MAIL" MaxLength="50" runat="server" Width="95%" onkeypress="RowChanged(this);" Text='<%# Bind("E_MAIL") %>'  />
          <asp:RegularExpressionValidator ID="RegularExpressionValidator1" ValidationGroup="EDIT" ForeColor="Red"  runat="server"  ControlToValidate="txtE_MAIL" SetFocusOnError="true" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" ErrorMessage="Invalid Email" BorderStyle="None"></asp:RegularExpressionValidator>
        </td>
        <td>
          <asp:TextBox ID="txtPARENT_DEPT_ID" MaxLength="17" runat="server" Width="95%" onchange="RowChanged(this);" Text='<%# Bind("PARENT_DEPT_ID") %>' />
          <asp:CompareValidator ID="CompareValidator1" runat="server" ErrorMessage="不可與部門代號相同" ControlToValidate="txtPARENT_DEPT_ID" ControlToCompare="txtDEPT_ID_G" ValidationGroup="EDIT" Operator="NotEqual" ForeColor="Red" SetFocusOnError="true"></asp:CompareValidator>
        </td>
        
      </tr>
    </ItemTemplate>
    <LayoutTemplate>
      <table id="tb2" runat="server">
        <tr id="Tr1" runat="server">
          <td id="Td1" runat="server">
            <table id="tb1" runat="server" border="1" style="background-color: #FFFFFF; border-collapse: collapse; border-color: #999999; border-style: none; border-width: 1px; font-family: Verdana, Arial, Helvetica, sans-serif;">
              <tr id="Tr2" runat="server" style="background-color: #FFFBD6; color: #333333;">
                <th id="Th1" style="width: 15%" runat="server"></th>
                <th id="Th2" style="width: 15%" runat="server">部門代號</th>
                <th id="Th3" style="width: 20%" runat="server">部門名稱</th>
                <th id="Th6" style="width: 15%" runat="server">部門主管</th>
                <th id="Th5" style="width: 20%" runat="server">站所特定E-Mail</th>
                <th id="Th4" style="width: 15%" runat="server">上層部門代號</th>
                
              </tr>
              <tr id="itemPlaceholder" runat="server">
              </tr>
            </table>
          </td>
        </tr>
        <tr id="Tr3" runat="server">
          <td id="Td2" runat="server" style="text-align: left; background-color: #FFCC66; font-family: Verdana, Arial, Helvetica, sans-serif; color: #333333;">
            <asp:DataPager ID="DataPager1" runat="server" PagedControlID="DV1" PageSize="10">
              <Fields>
                <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowLastPageButton="True" FirstPageText="第一頁" LastPageText="最後一頁" NextPageText="下一頁" PreviousPageText="上一頁" />
              </Fields>
            </asp:DataPager>
            <asp:Label ID="lbl_seq" runat="server" Text="第" />
            <asp:DropDownList ID="uxGoToPageDropDownList" runat="server" AutoPostBack="True"
              OnSelectedIndexChanged="uxGoToPageDropDownList_SelectedIndexChanged" />
            /
            <asp:Label ID="lbl_total_page_count" runat="server" /><asp:Label ID="lbl_page" runat="server" Text="頁" />
            每頁
            <asp:DropDownList ID="uxOnePageCountDropDownList" runat="server"
              AutoPostBack="True"
              OnSelectedIndexChanged="uxOnePageCountDropDownList_SelectedIndexChanged">
              <asp:ListItem>10</asp:ListItem>
              <asp:ListItem>20</asp:ListItem>
              <asp:ListItem>30</asp:ListItem>
            </asp:DropDownList>筆
             <asp:Label ID="lbl_total" runat="server" Text="總筆數 : " />
            <asp:Label ID="lbl_total_counter" runat="server" />
          </td>
        </tr>
      </table>
    </LayoutTemplate>
  </asp:ListView>

    <asp:ValidationSummary ID="ValidationSummary1" runat="server" />
  <br />



</asp:Content>

